﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Threading;
using SMSGateway.Threading;

namespace ProcessesSMS
{
    /// <summary>
    /// Summary description for MOWorkItem.
    /// </summary>

    public class MOWorkItem : WorkItem
    {
        #region Properties
        private SMS_MO MO;
        #endregion


        public MOWorkItem(int MO_ID, string UserID, string ServiceID, string CommandCode, string MessageInfo, int RequestID, DateTime RequestTime)
        {
            //
            // TODO: Add constructor logic here
            //
            MO = new SMS_MO(MO_ID, UserID, ServiceID, CommandCode.ToUpper(), MessageInfo, RequestID, RequestTime);
        }

        public MOWorkItem(int MO_ID, string UserID, string ServiceID, string CommandCode, string MessageInfo, int RequestID, DateTime RequestTime, int count)
        {
            //
            // TODO: Add constructor logic here
            //
            MO = new SMS_MO(MO_ID, UserID, ServiceID, CommandCode.ToUpper(), MessageInfo, RequestID, RequestTime, count);
        }

        public override void Perform()
        {
            #region VIT
            //Kiem tra gioi han ---------------------------------------------------------            
            SMS_Limit CheckLimit = new SMS_Limit();
            string Limit = CheckLimit.OverLimit(MO.UserID, MO.CommandCode, MO.ServiceID);
            if (Limit != "")
            {
                SMS_MT _MT;
                _MT = new SMS_MT(MO);
                SMS_STR TMSTR = new SMS_STR();
                _MT.AddMessage(MO.UserID, Limit, SMS_ContentType.SMS_TEXT);
                _MT.MsgType = SMS_MsgType.SMS_TINHTIEN;
                _MT.Insert();
                return;
            }
            //----------------------------------------------------------------------------

            #region TC
            if (MO.CommandCode.ToUpper() == "TC")
            {
                TC TC = new TC(MO);
                TC.run();
            }
            #endregion
            /*
                 * #region CHUNG KHOAN
            if (MO.CommandCode.ToUpper() == "CK" || MO.CommandCode.ToUpper() == "CK1")
			{
				CKVN CKVN = new CKVN(MO);
				CKVN.run();
			}	
			#endregion
            #region VANG
            else if (MO.CommandCode.ToUpper() == "GV" || MO.CommandCode.ToUpper() == "VANG" || MO.CommandCode.ToUpper() == "VANG1")//vang vn, vang tg
            {
                VANG VANG = new VANG(MO);
                VANG.run();
            }
            #endregion
            #region SILVER
            else if (MO.CommandCode.ToUpper() == "BAC" || MO.CommandCode.ToUpper() == "SILVER" || MO.CommandCode.ToUpper() == "SILVER1")//bac, silver
            {
                SILVER SILVER = new SILVER(MO);
                SILVER.run();
            }
            #endregion
            #region PLATINUM
            else if (MO.CommandCode.ToUpper() == "PT" || MO.CommandCode.ToUpper() == "PT1")//Platinum
            {
                PLATINUM PLATINUM = new PLATINUM(MO);
                PLATINUM.run();
            }
            #endregion
            #region DAU
            else if (MO.CommandCode.ToUpper() == "DAU" || MO.CommandCode.ToUpper() == "DAU1")//gia dau
            {
                DAU DAU = new DAU(MO);
                DAU.run();
            }
            #endregion
            #region Ty gia ngoai te
            else if (MO.CommandCode.ToUpper() == "TG" || MO.CommandCode.ToUpper() == "TG1" || MO.CommandCode.ToUpper() == "TYGIA")//Ty gia ngoai te
            {
                TYGIA TYGIA = new TYGIA(MO);
                TYGIA.run();
            }
            else if (MO.CommandCode.ToUpper() == "T")//
            {
                _TEMP _TEMP = new _TEMP(MO);
                _TEMP.run();
            }
            #endregion
            #region SMS XO SO
            else if((MO.CommandCode.ToUpper() == "XSTD") || (MO.CommandCode.ToUpper() == "XSMB") || (MO.CommandCode.ToUpper() == "SXTD") || (MO.CommandCode.ToUpper() == "SXMB"))//1.ket qua xs TD moi nhat, 2. ket qua xs TD theo ngay, 3.tuong thuat truc tiep ket qua, cho nhan ket qua
			{
				XOSO XOSO = new XOSO(MO);
				XOSO.run();
			}
            else if ((MO.CommandCode.ToUpper() == "XS") || (MO.CommandCode.ToUpper() == "SX"))//xo so cac tinh mien Trung va mien Nam, cho nhan ket qua cac tinh
			{
				XOSO_MT XOSO_MT = new XOSO_MT(MO);
				XOSO_MT.run();
			}
            else if ((MO.CommandCode.ToUpper() == "XSMT") || (MO.CommandCode.ToUpper() == "SXMT"))//xem toan bo ket qua xo so mien Trung ngay moi nhat
			{
				XSMT XSMT = new XSMT(MO);
				XSMT.run();
			}
            else if ((MO.CommandCode.ToUpper() == "XSMN") || (MO.CommandCode.ToUpper() == "SXMN"))//xem toan bo ket qua xo so mien Nam ngay moi nhat
			{			
				XSMN XSMN = new XSMN(MO);
				XSMN.run();
			}
			else if(MO.CommandCode.ToUpper() == "DS")//thong ke
			{
				DS DS = new DS(MO);
				DS.run();
			}
			else if (MO.CommandCode.ToUpper() == "DD") // DU DOAN SO PHAT TAI
			{
				XOSO_DD XOSO_DD = new XOSO_DD(MO);
				XOSO_DD.run();
			}
            else if ((MO.CommandCode.ToUpper() == "CAU") || (MO.CommandCode.ToUpper() == "CAUMB") || (MO.CommandCode.ToUpper() == "CAUTD")) // CAU LO TUNG BUNG
			{
				XOSO_CAU XOSO_CAU = new XOSO_CAU(MO);
				XOSO_CAU.run();
			}
            else if ((MO.CommandCode.ToUpper() == "SOI") || (MO.CommandCode.ToUpper() == "SOIMB") || (MO.CommandCode.ToUpper() == "SOITD")) // SOI SO DAI LOC
			{
				XOSO_SOI XOSO_SOI = new XOSO_SOI(MO);
				XOSO_SOI.run();
            }
            else if ((MO.CommandCode.ToUpper() == "PL") || (MO.CommandCode.ToUpper() == "PLTD")) // Phat loc
            {
                XOSO_PL XOSO_PL = new XOSO_PL(MO);
                XOSO_PL.run();
            }
            #endregion	            				
			#region Cu phap nap tien cua VietWeb
            else if (MO.CommandCode.ToUpper() == "TLH")
			{
				VIETWEB VIETWEB = new VIETWEB(MO);
				VIETWEB.run();
			}
			#endregion
			#region Cu phap nap tien NAP
			else if (MO.CommandCode.ToUpper()=="NAP")
			{
				CAUVANG CAUVANG = new CAUVANG(MO);
				CAUVANG.run();
			}
			#endregion
			#region Cu phap THOI TIET
			else if (MO.CommandCode.ToUpper()=="TT")
			{
				THOITIET THOITIET = new THOITIET(MO);
				THOITIET.run();
			}
			#endregion            
			#region Con thoi thi truong
			else if ((MO.CommandCode.ToUpper()=="TL"))
			{
				CONTHOITHITRUONG CONTHOITHITRUONG = new CONTHOITHITRUONG(MO);
				CONTHOITHITRUONG.run();
			}
			#endregion			
            #region Nhac chuong
            else if (MO.CommandCode.ToUpper() == "NC" || MO.CommandCode.ToUpper() == "TNC")
            {
                TAINHACCHUONG TAINHACCHUONG = new TAINHACCHUONG(MO);
                TAINHACCHUONG.run();
            }
            #endregion
            #region Hinh anh
            //else if (MO.CommandCode.ToUpper() == "IM")
            //{
            //    IMG IM = new IMG(MO);
            //    IM.run();
            //}
            #endregion
            #region Bong Da 
            else if (MO.CommandCode.ToUpper() == "BD")//tam thoi bo BC cua bong da thay vao VOTE
            {
                BONGDA BONGDA = new BONGDA(MO);
                BONGDA.run();
            }
            #endregion            
            #region SKY
            else if (MO.CommandCode.ToUpper() == "A")
            {
                A A = new A(MO);
                A.run();
            }
            #endregion
            #region NAVIS
            else if ((MO.CommandCode.ToUpper() == "CT") || (MO.CommandCode.ToUpper() == "CP") || (MO.CommandCode.ToUpper() == "ND") || (MO.CommandCode.ToUpper() == "KN") || (MO.CommandCode.ToUpper() == "TV") || (MO.CommandCode.ToUpper() == "CL"))
            {
                NAVIS NAVIS = new NAVIS(MO);
                NAVIS.run();
            }
            #endregion
            #region Download VTOOL
            else if (MO.CommandCode.ToUpper() == "VT")
            {
                VTOOL VTOOL = new VTOOL(MO);
                VTOOL.run();
            }
            #endregion
            #region SMS EDUCATION
            else if ((MO.CommandCode.ToUpper() == "QHT") || (MO.CommandCode.ToUpper() == "SD"))
            {
                EDUCATION EDUCATION = new EDUCATION(MO);
                EDUCATION.run();               
            }
            #endregion
            #region DANHBA24H
            else if ((MO.CommandCode.ToUpper() == "KHD") || (MO.CommandCode.ToUpper() == "DBN") || (MO.CommandCode.ToUpper() == "UPT")
                || (MO.CommandCode.ToUpper() == "UPE") || (MO.CommandCode.ToUpper() == "UPS") || (MO.CommandCode.ToUpper() == "DB")
                || (MO.CommandCode.ToUpper() == "DBH") || (MO.CommandCode.ToUpper() == "UDB") || (MO.CommandCode.ToUpper() == "KT")
                || (MO.CommandCode.ToUpper() == "KTU") || (MO.CommandCode.ToUpper() == "KTB"))
            {
                DANHBA24H DANHBA24H = new DANHBA24H(MO);
                DANHBA24H.run();
            }
            #endregion
            #region Dau Gia
            else if (MO.CommandCode.ToUpper() == "DG1" || MO.CommandCode.ToUpper() == "DG2" || MO.CommandCode.ToUpper() == "DG3" || MO.CommandCode.ToUpper() == "DG4" || MO.CommandCode.ToUpper() == "DG5")
            {
                DAUGIA DAUGIA = new DAUGIA(MO);
                DAUGIA.run();
            }
            #endregion
            #region Tour Green
            else if (MO.CommandCode.ToUpper() == "MK" || MO.CommandCode.ToUpper() == "HH")
            {
                TOURGREEN TOURGREEN = new TOURGREEN(MO);
                TOURGREEN.run();
            }
            #endregion
            #region VOTE QUANG NGAI
            else if (MO.CommandCode.ToUpper() == "IM")
            {
                VOTE VOTE = new VOTE(MO);
                VOTE.run();
            }
            #endregion
            #region VOTE 2 (TUU's Hidden Beauty 2012)
            else if (MO.CommandCode.ToUpper() == "TUU")
            {
                VOTE_1 VOTE_1 = new VOTE_1(MO);
                VOTE_1.run();
            }
            #endregion
            #region Vuon tao xanh
            else if (MO.CommandCode.ToUpper() == "KTX")
            {
                VUONTAOXANH VUONTAOXANH = new VUONTAOXANH(MO);
                VUONTAOXANH.run();
            }
            #endregion
            #region ONE MOBILE
            else if (MO.CommandCode.ToUpper() == "X1" || MO.CommandCode.ToUpper() == "BT" || MO.CommandCode.ToUpper() == "LV" || MO.CommandCode.ToUpper() == "X6"
                || MO.CommandCode.ToUpper() == "KEP" || MO.CommandCode.ToUpper() == "LO" || MO.CommandCode.ToUpper() == "DE" || MO.CommandCode.ToUpper() == "SC"
                || MO.CommandCode.ToUpper() == "LT" || MO.CommandCode.ToUpper() == "X9" || MO.CommandCode.ToUpper() == "L8")
            {
                ONEMOBILE ONEMOBILE = new ONEMOBILE(MO);
                ONEMOBILE.run();
            }
            #endregion
            #region UH Bao giao duc 
            else if (MO.CommandCode.ToUpper() == "UH")
            {
                BAOGIAODUC BAOGIAODUC = new BAOGIAODUC(MO);
                BAOGIAODUC.run();
            }
            #endregion
            #region Cty truyen thong Anh Minh
            else if (MO.CommandCode.ToUpper() == "SA" || MO.CommandCode.ToUpper() == "TB" || MO.CommandCode.ToUpper() == "B1"
                || MO.CommandCode.ToUpper() == "B2" || MO.CommandCode.ToUpper() == "B3" || MO.CommandCode.ToUpper() == "B4"
                || MO.CommandCode.ToUpper() == "B5" || MO.CommandCode.ToUpper() == "B6"
                || MO.CommandCode.ToUpper() == "S1" || MO.CommandCode.ToUpper() == "S2" || MO.CommandCode.ToUpper() == "S3"
                || MO.CommandCode.ToUpper() == "S4" || MO.CommandCode.ToUpper() == "S5" || MO.CommandCode.ToUpper() == "S6"
                || MO.CommandCode.ToUpper() == "S7" || MO.CommandCode.ToUpper() == "S8" || MO.CommandCode.ToUpper() == "S9"
                || MO.CommandCode.ToUpper() == "DA" || MO.CommandCode.ToUpper() == "DK"
                || MO.CommandCode.ToUpper() == "DE"|| MO.CommandCode.ToUpper() == "LT"|| MO.CommandCode.ToUpper() == "BL"
                || MO.CommandCode.ToUpper() == "AD" || MO.CommandCode.ToUpper() == "KEP" || MO.CommandCode.ToUpper() == "HOT"
                || MO.CommandCode.ToUpper() == "HN" || MO.CommandCode.ToUpper() == "TA" || MO.CommandCode.ToUpper() == "NH"
                || MO.CommandCode.ToUpper() == "VOV" || MO.CommandCode.ToUpper() == "FM" || MO.CommandCode.ToUpper() == "YEU"
                || MO.CommandCode.ToUpper() == "HC")
            {
                ANHMINH ANHMINH = new ANHMINH(MO);
                ANHMINH.run();
            }
            #endregion
            #region VIS 
            else if (MO.CommandCode.ToUpper() == "AK" || MO.CommandCode.ToUpper() == "BD" || MO.CommandCode.ToUpper() == "AN"
                || MO.CommandCode.ToUpper() == "AT" || MO.CommandCode.ToUpper() == "SC" || MO.CommandCode.ToUpper() == "LK"
                || MO.CommandCode.ToUpper() == "LS" || MO.CommandCode.ToUpper() == "LX" || MO.CommandCode.ToUpper() == "OK"
                || MO.CommandCode.ToUpper() == "SH" || MO.CommandCode.ToUpper() == "SON" || MO.CommandCode.ToUpper() == "VIP"
                || MO.CommandCode.ToUpper() == "EK" || MO.CommandCode.ToUpper() == "BK" || MO.CommandCode.ToUpper() == "TA"
                || MO.CommandCode.ToUpper() == "L6" || MO.CommandCode.ToUpper() == "SC"
                || MO.CommandCode.ToUpper() == "SK" || MO.CommandCode.ToUpper() == "X2" || MO.CommandCode.ToUpper() == "X8"
                || MO.CommandCode.ToUpper() == "VUA")
            {
                VIS VIS = new VIS(MO);
                VIS.run();
            }
            #endregion
                 
            #region Test he thong
            else if (MO.CommandCode.ToUpper() == "TEST")
            {
                TEST TEST = new TEST(MO);
                TEST.run();
            }
            #endregion

            #region Test he thong TUU's Hidden Beauty 2012
            else if (MO.CommandCode.ToUpper() == "TESTT")
            {
                TESTT TESTs = new TESTT(MO);
                TESTs.run();
            }
            else if (MO.CommandCode.ToUpper() == "TDT")
            {
                SMS_MT mts;
                mts = new SMS_MT(MO);
                SMS_STR TMSTRs = new SMS_STR();
                mts.AddMessage(MO.UserID, "Xin chao TDT :)", SMS_ContentType.SMS_TEXT);
                mts.MsgType = SMS_MsgType.SMS_KHONGTINHTIEN;
                mts.Insert();
                return;
            }
             */
            else if (MO.CommandCode.ToUpper() == "TDT")
            {
                SMS_MT mts;
                mts = new SMS_MT(MO);
                SMS_STR TMSTRs = new SMS_STR();
                mts.AddMessage(MO.UserID, "Xin chao TDT (._.)", SMS_ContentType.SMS_TEXT);
                mts.MsgType = SMS_MsgType.SMS_KHONGTINHTIEN;
                mts.Insert();
                return;
            }
            else if (MO.CommandCode.ToUpper() == "XM")
            {
                XACMINHHANGTHAT hanel = new XACMINHHANGTHAT(MO);
                hanel.run();
            }
            else
            {
                SMS_MT _MT;
                _MT = new SMS_MT(MO);
                SMS_STR TMSTR = new SMS_STR();
                _MT.AddMessage(MO.UserID, ConfigSettings.ReadSetting("SMS_HELP"), SMS_ContentType.SMS_TEXT);
                _MT.MsgType = SMS_MsgType.SMS_TINHTIEN;
                _MT.Insert();
                return;
            }

            /*
        else
        {
            SMS_MT _MT;
            _MT = new SMS_MT(MO);
            SMS_STR TMSTR = new SMS_STR();
            _MT.AddMessage(MO.UserID, ConfigSettings.ReadSetting("SMS_HELP"), SMS_ContentType.SMS_TEXT);
            _MT.MsgType = SMS_MsgType.SMS_TINHTIEN;
            _MT.Insert();
            return;
        }
             */
            #endregion

        }
    }

}